//
//  RootViewController.m
//  UI19_UICollectionView
//
//  Created by dllo on 15/12/3.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "CustomCollectionViewCell.h"

@interface RootViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    // UICollectionViewLayout 是一个抽象类,我们一般使用它的子类
    UICollectionViewFlowLayout *flowL = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    
    // 最低限度行间距
    // 注意:
    // 1, 系统会尽可能靠近此参数, 并保证不会小于
    // 2, 垂直于滑动方向即为行!
    flowL.minimumLineSpacing = 50;
    
    // 列间距
    flowL.minimumInteritemSpacing = 100;
    
    // 单元大小
    flowL.itemSize = CGSizeMake(100, 100);
    
    // 区头间距
    flowL.headerReferenceSize = CGSizeMake(50, 50);
    
//    // 区脚间距
//    flowL.footerReferenceSize = CGSizeMake(50, 50);
    
    // 与屏幕四边的间距
    flowL.sectionInset = UIEdgeInsetsMake(10, 5, 10, 5);
    
    // 滚动方向
    flowL.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowL];
    
//    collectionV.backgroundColor = [UIColor purpleColor];
    collectionV.delegate = self;
    collectionV.dataSource = self;
    [self.view addSubview:collectionV];
    [collectionV release];
    
    // 注册自定义cell
    [collectionV registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"点击某个cell");
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 3;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 100;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.label.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    return cell;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
